// Copyright 2012 Square, Inc.
package org.assertj.ohos.api.app;

import ohos.aafwk.ability.Ability;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;
import org.assertj.ohos.api.content.AbstractContextAssert;
import java.io.IOException;
import static ohos.bundle.AbilityInfo.DisplayOrientation.*;
import static org.assertj.ohos.internal.BitmaskUtils.buildNamedValueString;
import static org.assertj.core.api.Assertions.assertThat;

public abstract class AbstractActivityAssert<S extends AbstractActivityAssert<S, A>, A extends Ability>
    extends AbstractContextAssert<S, A> {
  public AbstractActivityAssert(A actual, Class<S> selfType) {
    super(actual, selfType);
  }

  public S hasRequestedOrientation(int orientation) {
    isNotNull();
    int actualOrientation = actual.getDisplayOrientation();
    assertThat(actualOrientation) //
        .overridingErrorMessage("Expected orientation <%s> but was <%s>.",
            screenOrientationToString(orientation), screenOrientationToString(actualOrientation)) //
        .isEqualTo(orientation);
    return myself;
  }

  public S hasTitle(CharSequence title) {
    isNotNull();
    CharSequence actualTitle = actual.getAbilityInfo().getLabel();
    assertThat(actualTitle) //
        .overridingErrorMessage("Expected title <%s> but was <%s>.", title, actualTitle) //
        .isEqualTo(title);
    return myself;
  }

  public S hasTitle(int resId) throws NotExistException, WrongTypeException, IOException {
    isNotNull();
    return hasTitle(actual.getResourceManager().getElement(resId).getString(resId));
  }

/* // TODO: wang, not found in ohos
  public S hasTitleColor(int color) {
    isNotNull();
    int actualColor = actual.getTitleColor();
    assertThat(actualColor) //
        .overridingErrorMessage("Expected title color <%s> but was <%s>.",
            Integer.toHexString(color), Integer.toHexString(actualColor)) //
        .isEqualTo(color);
    return myself;
  }
*/

  public S hasWindowFocus() {
    isNotNull();
    assertThat(actual.hasWindowFocus()) //
        .overridingErrorMessage("Expected to have focus but was not focused.") //
        .isTrue();
    return myself;
  }

  public S isChangingConfigurations() {
    isNotNull();
    assertThat(actual.isUpdatingConfigurations()) //
        .overridingErrorMessage("Expected changing configurations but was not changing.") //
        .isTrue();
    return myself;
  }

  public S isNotChangingConfigurations() {
    isNotNull();
    assertThat(actual.isUpdatingConfigurations()) //
        .overridingErrorMessage("Expected not to be changing configurations but was changing.") //
        .isFalse();
    return myself;
  }

/* // TODO: wang, not found in ohos
  public S isChild() {
    isNotNull();
    assertThat(actual.isChild()) //
        .overridingErrorMessage("Expected to be a child but was not a child.") //
        .isTrue();
    return myself;
  }
*/

/* // TODO: wang, not found in ohos
  public S isNotChild() {
    isNotNull();
    assertThat(actual.isChild()) //
        .overridingErrorMessage("Expected not to be a child but was a child.") //
        .isFalse();
    return myself;
  }
*/

  public S isDestroyed() {
    isNotNull();
    assertThat(actual.isTerminating()) //
        .overridingErrorMessage("Expected to be destroyed but was not destroyed.") //
        .isTrue();
    return myself;
  }

  public S isNotDestroyed() {
    isNotNull();
    assertThat(actual.isTerminating()) //
        .overridingErrorMessage("Expected not to be destroyed but was destroyed.") //
        .isFalse();
    return myself;
  }

  public S isFinishing() {
    isNotNull();
    assertThat(actual.isTerminating()) //
        .overridingErrorMessage("Expected to be finishing but was not finishing.") //
        .isTrue();
    return myself;
  }

  public S isNotFinishing() {
    isNotNull();
    assertThat(actual.isTerminating()) //
        .overridingErrorMessage("Expected to not be finishing but was finishing.") //
        .isFalse();
    return myself;
  }

/* // TODO: wang, not found in ohos
  public S isImmersive() {
    isNotNull();
    assertThat(actual.isImmersive()) //
        .overridingErrorMessage("Expected to be immersive but was not.") //
        .isTrue();
    return myself;
  }
*/

/* // TODO: wang, not found in ohos
  public S isNotImmersive() {
    isNotNull();
    assertThat(actual.isImmersive()) //
        .overridingErrorMessage("Expected to not be immersive but was.") //
        .isFalse();
    return myself;
  }
*/

/* // TODO: wang, not found in ohos
  public S isTaskRoot() {
    isNotNull();
    assertThat(actual.isTaskRoot()) //
        .overridingErrorMessage("Expected to be task root but was not task root.") //
        .isTrue();
    return myself;
  }
*/

/* // TODO: wang, not found in ohos
  public S isNotTaskRoot() {
    isNotNull();
    assertThat(actual.isTaskRoot()) //
        .overridingErrorMessage("Expected not to be task root but was task root.") //
        .isFalse();
    return myself;
  }
*/

  public static String screenOrientationToString(int orientation) {
    return buildNamedValueString(orientation)
        .value(UNSPECIFIED.ordinal(), "unspecified")
        .value(LANDSCAPE.ordinal(), "landscape")
        .value(PORTRAIT.ordinal(), "portrait")
/*      // TODO: wang, not found in ohos
        .value(SCREEN_ORIENTATION_USER, "user")
        .value(SCREEN_ORIENTATION_BEHIND, "behind")
        .value(SCREEN_ORIENTATION_SENSOR, "sensor")
        .value(SCREEN_ORIENTATION_NOSENSOR, "nosensor")
        .value(SCREEN_ORIENTATION_SENSOR_LANDSCAPE, "sensor_landscape")
        .value(SCREEN_ORIENTATION_SENSOR_PORTRAIT, "sensor_portrait")
        .value(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, "reverse_landscape")
        .value(SCREEN_ORIENTATION_REVERSE_PORTRAIT, "reverse_portrait")
        .value(SCREEN_ORIENTATION_FULL_SENSOR, "full_sensor")
        .value(SCREEN_ORIENTATION_USER_LANDSCAPE, "user_landscape")
        .value(SCREEN_ORIENTATION_USER_PORTRAIT, "user_portrait")
        .value(SCREEN_ORIENTATION_FULL_USER, "full_user")
        .value(SCREEN_ORIENTATION_LOCKED, "locked")*/
        .get();
  }
}
